#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>

using namespace std;

int main() {
    vector<vector<uint64_t>> dp;
    ifstream file ("./81.txt");
    string line;
    while (getline(file, line)) {
        vector<uint64_t> v;
        stringstream ss {line};
        string token;
        while (getline(ss, token, ',')) 
            v.push_back(stoi(token));
        dp.push_back(v);
    }
    file.close();
#if 0
    vector<vector<uint64_t>> dp {
        {131, 673, 234, 103, 18},
        {201, 96, 342, 965, 150},
        {630, 803, 746, 422, 111},
        {537, 699, 497, 121, 956},
        {805, 732, 524, 37, 331},
    };
#endif
    int n = dp.size();
    for (int i = n - 1; i >= 0; --i) {
        for (int j = n - 1; j >= 0; --j) {
            if (i == n - 1 && j == n - 1)
                continue;
            if (i == n - 1) {
                dp[i][j] += dp[i][j + 1];
            } else if (j == n - 1) {
                dp[i][j] += dp[i + 1][j];
            } else {
                dp[i][j] += min(dp[i + 1][j], dp[i][j + 1]);
            }
        }
    }
    cout << "Minimum path sum: " << dp[0][0] << endl;
}